package com.app.manage.moudles.confs.controller;




import com.app.manage.moudles.confs.entity.TGroup;
import com.app.manage.moudles.confs.service.TGroupService;
import com.app.manage.moudles.server.entity.TServer;
import com.app.manage.utils.PageSearch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.app.manage.utils.Rsp;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * 组别(TGroup)表控制层
 *
 * @author makejava
 * @since 2025-05-20 11:47:14
 */
@RestController
@RequestMapping("group")
public class TGroupController  {
    /**
     * 服务对象
     */
    @Resource
    private TGroupService tGroupService;


    @GetMapping("listGroup")
    public Rsp listGroup(){
        return Rsp.success(tGroupService.list());
    }


    @PostMapping("pageList")
    public Rsp pageList(@RequestBody PageSearch<TGroup> s){
        LambdaQueryWrapper<TGroup> query = new LambdaQueryWrapper<>();
        query.like(StringUtils.isNotEmpty(s.getDomain().getGroupName()),TGroup::getGroupName,s.getDomain().getGroupName());
        return Rsp.success(tGroupService.page(Page.of(s.getPageNum(),s.getPageSize()),query));

    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getById")
    public Rsp selectOne( Integer id) {
        return Rsp.success(this.tGroupService.getById(id));
    }

    @PostMapping("save")
    public Rsp saveData(@RequestBody TGroup tGroup){
        String res = tGroupService.saveData(tGroup);
        if(StringUtils.isNotEmpty(res)){
            return Rsp.fail(res);
        }
        return Rsp.success("新增完成");
    }

    @PostMapping("remove")
    public Rsp remove(String ids){
        if(StringUtils.isEmpty(ids)){
            return Rsp.fail("请选择需要删除的数据！");
        }
        String res = tGroupService.removeData(Arrays.asList(ids.split(",")));
        if(StringUtils.isNotEmpty(res)){
            return Rsp.fail(res);
        }
        return Rsp.success("删除完成");
    }

}

